<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.vsg.stock.basic.domain.mybatis.BalanceLineProxy">


	<resultMap id="BalanceLineProxyResult" type="org.vsg.stock.basic.domain.mybatis.BalanceLineProxy">
		<id property="lineId" column="LINE_ID" />
		<result property="stockCode" column="STOCK_CODE"/>
		<result property="form" column="FORM"/>
	</resultMap>

	<!-- insert statment -->
	<insert id="insertBalanceLine" parameterType="org.vsg.stock.basic.domain.mybatis.BalanceLineProxy">
		INSERT INTO balance_line ( line_id , stock_code , form)
		values (#{lineId} , #{stockCode} , #{form})
	</insert>
	
	<insert id="insertBalanceLinePoint" parameterType="org.vsg.stock.basic.domain.mybatis.BalanceLineKeyPointProxy">
		INSERT INTO balance_line_keypoint ( line_id , ref_date , price , price_type)
		values ( #{lineId}, #{refDate} , #{price} , #{priceType} )
	</insert>
	
	<select id="findExistedBalanineByPoint" parameterType="map" resultType="map">
		select 
			line.line_id,form,price_type,
			point.price AS PRICE ,
			point.ref_date AS REF_DATE 
			from balance_line AS line 
			inner join balance_line_keypoint_m AS mapping on line.line_id = mapping.line_id
			inner join balance_line_keypoint AS point on mapping.point_id = point.point_id
		where line.stock_code=#{stockCode} AND line.form=#{form} 
			AND point.price &lt;=  #{maxPrice}	AND point.price &gt;= #{minPrice}
	</select>
	


</mapper>
